package acwing;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing.QuestionsPractice
 * @File : Q4946.java
 * @Author : WangRuoyu
 * @Date : 2023/4/1 19:17
 */

import java.io.*;
import java.util.Arrays;

public class Q4946 {
    static final int N = 100010;
    static int[] h = new int[N];
    static int[] color;
    static int[] e = new int[N];
    static int[] next = new int[N];
    static int[] count = new int[N];
    static int idx = 0;
    static int n;
    static int m;
    static int res = 0;

    static void add(int a, int b) {
        e[idx] = b;
        next[idx] = h[a];
        h[a] = idx;
        idx++;
    }

    static void dfs(int u, int cnt, int father, int max) {
        if (color[u] == 1) {
            cnt++;
            max = Math.max(cnt, max);
        } else {
            cnt = 0;
        }
        if (count[u] == 1 && max <= m) {
            res++;
        }

        for (int i = h[u]; i != -1; i = next[i]) {
            if (e[i] != father) {
                dfs(e[i], cnt, u, max);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        Arrays.fill(h, -1);
        String[] words = br.readLine().split(" ");
        n = Integer.parseInt(words[0]);
        m = Integer.parseInt(words[1]);
        color = new int[n + 1];
        words = br.readLine().split(" ");
        for (int i = 1; i <= n; ++i) {
            color[i] = Integer.parseInt(words[i - 1]);
        }
        for (int i = 0; i < n - 1; ++i) {
            words = br.readLine().split(" ");
            int a = Integer.parseInt(words[0]);
            int b = Integer.parseInt(words[1]);
            add(a, b);
            add(b, a);
            count[a]++;
            count[b]++;
        }

        dfs(1, 0, -1, 0);

        System.out.println(res);
    }
}
